﻿using System;
using System.Data;
using System.Collections.Generic;
using Maticsoft.Common;
using Lawyer.Model;
namespace Lawyer.BLL
{
	/// <summary>
	/// AgencyInfo
	/// </summary>
	public partial class AgencyInfo
	{
		private readonly Lawyer.DAL.AgencyInfo dal=new Lawyer.DAL.AgencyInfo();
		public AgencyInfo()
		{}
		#region  Method
		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(string AgencyID)
		{
			return dal.Exists(AgencyID);
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(Lawyer.Model.AgencyInfo model)
		{
			return dal.Add(model);
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(Lawyer.Model.AgencyInfo model)
		{
			return dal.Update(model);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(string AgencyID)
		{
			
			return dal.Delete(AgencyID);
		}
		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool DeleteList(string AgencyIDlist )
		{
			return dal.DeleteList(AgencyIDlist );
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Lawyer.Model.AgencyInfo GetModel(string AgencyID)
		{
			
			return dal.GetModel(AgencyID);
		}

		/// <summary>
		/// 得到一个对象实体，从缓存中
		/// </summary>
		public Lawyer.Model.AgencyInfo GetModelByCache(string AgencyID)
		{
			
			string CacheKey = "AgencyInfoModel-" + AgencyID;
			object objModel = Maticsoft.Common.DataCache.GetCache(CacheKey);
			if (objModel == null)
			{
				try
				{
					objModel = dal.GetModel(AgencyID);
					if (objModel != null)
					{
						int ModelCache = Maticsoft.Common.ConfigHelper.GetConfigInt("ModelCache");
						Maticsoft.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
					}
				}
				catch{}
			}
			return (Lawyer.Model.AgencyInfo)objModel;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			return dal.GetList(strWhere);
		}
		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			return dal.GetList(Top,strWhere,filedOrder);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<Lawyer.Model.AgencyInfo> GetModelList(string strWhere)
		{
			DataSet ds = dal.GetList(strWhere);
			return DataTableToList(ds.Tables[0]);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<Lawyer.Model.AgencyInfo> DataTableToList(DataTable dt)
		{
			List<Lawyer.Model.AgencyInfo> modelList = new List<Lawyer.Model.AgencyInfo>();
			int rowsCount = dt.Rows.Count;
			if (rowsCount > 0)
			{
				Lawyer.Model.AgencyInfo model;
				for (int n = 0; n < rowsCount; n++)
				{
					model = new Lawyer.Model.AgencyInfo();
					if(dt.Rows[n]["AgencyID"]!=null && dt.Rows[n]["AgencyID"].ToString()!="")
					{
					model.AgencyID=dt.Rows[n]["AgencyID"].ToString();
					}
					if(dt.Rows[n]["Name"]!=null && dt.Rows[n]["Name"].ToString()!="")
					{
					model.Name=dt.Rows[n]["Name"].ToString();
					}
					if(dt.Rows[n]["AgencyRate"]!=null && dt.Rows[n]["AgencyRate"].ToString()!="")
					{
						model.AgencyRate=Double.Parse(dt.Rows[n]["AgencyRate"].ToString());
					}
					if(dt.Rows[n]["Email"]!=null && dt.Rows[n]["Email"].ToString()!="")
					{
					model.Email=dt.Rows[n]["Email"].ToString();
					}
					if(dt.Rows[n]["City"]!=null && dt.Rows[n]["City"].ToString()!="")
					{
					model.City=dt.Rows[n]["City"].ToString();
					}
					if(dt.Rows[n]["Telphone"]!=null && dt.Rows[n]["Telphone"].ToString()!="")
					{
					model.Telphone=dt.Rows[n]["Telphone"].ToString();
					}
					if(dt.Rows[n]["Fax"]!=null && dt.Rows[n]["Fax"].ToString()!="")
					{
					model.Fax=dt.Rows[n]["Fax"].ToString();
					}
					if(dt.Rows[n]["Address"]!=null && dt.Rows[n]["Address"].ToString()!="")
					{
					model.Address=dt.Rows[n]["Address"].ToString();
					}
					if(dt.Rows[n]["AvatarURL"]!=null && dt.Rows[n]["AvatarURL"].ToString()!="")
					{
					model.AvatarURL=dt.Rows[n]["AvatarURL"].ToString();
					}
					if(dt.Rows[n]["Status"]!=null && dt.Rows[n]["Status"].ToString()!="")
					{
						model.Status=int.Parse(dt.Rows[n]["Status"].ToString());
					}
					if(dt.Rows[n]["Note"]!=null && dt.Rows[n]["Note"].ToString()!="")
					{
					model.Note=dt.Rows[n]["Note"].ToString();
					}
					if(dt.Rows[n]["CreatedBy"]!=null && dt.Rows[n]["CreatedBy"].ToString()!="")
					{
					model.CreatedBy=dt.Rows[n]["CreatedBy"].ToString();
					}
					if(dt.Rows[n]["CreatedDate"]!=null && dt.Rows[n]["CreatedDate"].ToString()!="")
					{
						model.CreatedDate=DateTime.Parse(dt.Rows[n]["CreatedDate"].ToString());
					}
					if(dt.Rows[n]["Updatedby"]!=null && dt.Rows[n]["Updatedby"].ToString()!="")
					{
					model.Updatedby=dt.Rows[n]["Updatedby"].ToString();
					}
					if(dt.Rows[n]["UpdatedDate"]!=null && dt.Rows[n]["UpdatedDate"].ToString()!="")
					{
						model.UpdatedDate=DateTime.Parse(dt.Rows[n]["UpdatedDate"].ToString());
					}
					modelList.Add(model);
				}
			}
			return modelList;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetAllList()
		{
			return GetList("");
		}

		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		//public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		//{
			//return dal.GetList(PageSize,PageIndex,strWhere);
		//}

		#endregion  Method

        
    }
}

